package com.tianqu.tms.core.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.exception.TmsException;

/**
* 单纯的页面跳转</p><br />
* @author liugang
*/
public class TmsForwardAction extends TmsAction {
	
	/** Logger */	
	private Logger logger = Logger.getLogger(this.getClass());
	/**
	 * <pre>
	 * 直接跳转到Strtus-Config配置的paramter参数指定的页面
	 * </pre>
	 * @param mapping 
	 * @param form 
	 * @param request HttpServlet
	 * @param response HttpServlet
	 * @param uc UserContext
	 * @return ActionForward
	 * @throws Exception
	 */
	protected ActionForward doAction(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response,
		UserContext uc)
		throws TmsException {
			
		logger.debug("ForwardAction#doAction called.");
		String path = mapping.getParameter();
			
		if (path == null) {
			// 调转地址取得错误时候，提示错误信息。
			logger.error( "No context-relative URI specified via the 'parameter' attribute");
			throw new TmsException("No context-relative URI specified via the \'parameter\' attribute");
		}

		ActionForward forward = new ActionForward(path);
		forward.setContextRelative(true); 
			
		return forward;
	}

}